-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Cache derive proc macro expansion with incremental query #145354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
This comment has been minimized.
This comment has been minimized.
Cache derive proc macro expansion with incremental query
} | ||
} | ||
|
||
impl<H: std::hash::Hasher> SpanEncoder for HashEncoder<H> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this use StableHasher? The regular Hash impl is only valid for a single rustc session.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something that wasn't answered in #129102 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I need to read up on the difference of usage of Hash
and StableHash
for incremental. I examined a few other query key types and a lot of them just #[derive(Hash)]
. I did the same for TokenStream
, but would appreciate guidance on if it is the Right Thing to do :)
/// Must be called while the `enter` function is active. | ||
fn with<F, R>(f: F) -> R | ||
where | ||
F: for<'a, 'b> FnOnce(&'b mut ExtCtxt<'a>, DeriveClient) -> R, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ExtCtxt contains a bunch of things that would need to be tracked by the query system for sound caching. And the rest could either be retrieved from the tcx
or be created from scratch to avoid having to use a thread local to bypass the query system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was discussed a bit in #129102 (comment) and a few comments right above it.
This comment has been minimized.
This comment has been minimized.
💔 Test for 21e746d failed: CI. Failed jobs:
|
This comment has been minimized.
This comment has been minimized.
@bors try |
This comment has been minimized.
This comment has been minimized.
Cache derive proc macro expansion with incremental query
The job Click to see the possible cause of the failure (guessed by this bot)
|
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test for b712f62 failed: CI. Failed jobs:
|
let macro_def_id = invoc_expn_data.macro_def_id.unwrap(); | ||
let proc_macro_crate_hash = tcx.crate_hash(macro_def_id.krate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done from inside the query, to force a dependency on crate_hash
, not as part of the key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my knowledge of the query infrastructure is quite limited 😅 How would that work? The key would be just LocalExpnId
and &TokenStream
, and then inside the query I would just call tcx.crate_hash
and throw away the results? 🤔
I looked into the benchmark failure on diesel, seems like I hold queries wrong somehow :) Any suggestions on what could be the case? Maybe the derived
|
This is a revival of #129102, originally implemented by @futile. Since it looks like they are not active currently, I'd like to push this work forward.
The first commit is squashed and rebased work from the original PR, with author attribution to futile. The rest of the commits are some additional comments that I created mostly for myself to understand what happens here. I also did some cleanups based on Vadim's review comments on the original PR, plus I refactored the TLS access a bit using
scoped_tls
.The biggest issue, as usually, are tests... I tried using
#[rustc_clean(..., loaded_from_disk = "derive_macro_expansion")]
, but the problem is that since this query cannot recover the original key from its hash, and thus its fingerprintstyle isFingerprintStyle::Opaque
, this crashes when I try to useloaded_from_disk
. Any suggestions from someone who actually understands the query system would be welcome 😅To answer one review question from the original PR: the
Hash
implementation forTokenStream
is indeed called, and it is needed since the stream forms a part of a query key. Not sure about theEncoder
Hash
implementation though.The last commit is WIP to enable the functionality by default for rustc-perf, I'll do another perf. run here.
TODO: document the new unstable flag
r? @petrochenkov